const img = document.querySelector('.thumb')
const file = document.querySelector('#iptFile')
const btn = document.querySelector('#btnChoose')
btn.addEventListener('click', function () {
  file.click()
})
try {
  file.addEventListener('change', async function () {
    console.log(this.files[0])
    if (!this.files[0]) return alert('该图片为空')
    const fd = new FormData()
    fd.append('avatar', this.files[0])
    const { data: res } = await axios.post(
      'http://ajax-api.itheima.net/api/file',
      fd
    )
    console.log(res)
    const url = res.data.url
    img.src = url
  })
} catch (error) {
  console.log(error)
}
